//
//  OrderTableViewCell.m
//  HWZB
//
//  Created by 许成雄 on 2017/4/20.
//  Copyright © 2017年 wonders. All rights reserved.
//

#import "OrderTableViewCell.h"
#import "UIImageView+Webcache.h"

@interface OrderTableViewCell()

@property (strong, nonatomic) UIImageView *pictureImageView;
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *numLabel;
@property (strong, nonatomic) UILabel *timeLabel;
@property (strong, nonatomic) UILabel *priceLabel;
@property (strong, nonatomic) UIImageView *arrowImageView;

@end

@implementation OrderTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
    
        self.pictureImageView = [[UIImageView alloc] initWithFrame:CGRectMake(TRANS_VALUE(10.0f), TRANS_VALUE(10.0f), TRANS_VALUE(60.0f), TRANS_VALUE(50.0f))];
        self.pictureImageView.contentMode = UIViewContentModeScaleAspectFit;
        self.pictureImageView.clipsToBounds = YES;
        self.pictureImageView.layer.cornerRadius = TRANS_VALUE(0.0f) / 2;
        [self.contentView addSubview:self.pictureImageView];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(TRANS_VALUE(75.0f), TRANS_VALUE(10.0f), TRANS_VALUE(120.0f), TRANS_VALUE(25.0f))];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:TRANS_VALUE(13.0f)];
        self.titleLabel.textColor = I_COLOR_33BLACK;
        self.titleLabel.text = @"中石化加油卡";
        [self.contentView addSubview:self.titleLabel];
        
        self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(TRANS_VALUE(75.0f), TRANS_VALUE(35.0f), TRANS_VALUE(100.0f), TRANS_VALUE(25.0f))];
        self.priceLabel.font = [UIFont systemFontOfSize:TRANS_VALUE(11.0f)];
        self.priceLabel.textColor = I_COLOR_33BLACK;
        self.priceLabel.text = @"合计: ￥1000元";
        [self.contentView addSubview:self.priceLabel];
        
        self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(TRANS_VALUE(210.0f), TRANS_VALUE(10.0f), TRANS_VALUE(90.0f), TRANS_VALUE(25.0f))];
        self.numLabel.font = [UIFont systemFontOfSize:TRANS_VALUE(11.0f)];
        self.numLabel.textAlignment = NSTextAlignmentRight;
        self.numLabel.textColor = I_COLOR_33BLACK;
        self.numLabel.text = @"数量: 1";
        [self.contentView addSubview:self.numLabel];
        
        self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(TRANS_VALUE(180.0f), TRANS_VALUE(35.0f), TRANS_VALUE(120.0f), TRANS_VALUE(25.0f))];
        self.timeLabel.font = [UIFont systemFontOfSize:TRANS_VALUE(11.0f)];
        self.timeLabel.textAlignment = NSTextAlignmentRight;
        self.timeLabel.textColor = I_COLOR_33BLACK;
        self.timeLabel.text = @"2017-05-07 00:05:13";
        [self.contentView addSubview:self.timeLabel];
        
        self.arrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(TRANS_VALUE(308.0f), TRANS_VALUE(30.0f), TRANS_VALUE(6.0f), TRANS_VALUE(10.0f))];
        self.arrowImageView.contentMode = UIViewContentModeScaleAspectFit;
        self.arrowImageView.backgroundColor = I_COLOR_WHITE;
        [self.arrowImageView setImage:[UIImage imageNamed:@"ic_me_arrow_black"]];
        [self.contentView addSubview:self.arrowImageView];
    }
    self.contentView.backgroundColor = I_COLOR_WHITE;
    
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setOrderInfo:(OrderInfo *)orderInfo {
    _orderInfo = orderInfo;
    if(orderInfo != nil) {
        NSString *titleStr = _orderInfo.productName != nil ? _orderInfo.productName : @"";
        self.titleLabel.text = titleStr;
        NSString *imageURL = [NSString stringWithFormat:@"%@",_orderInfo.imageUrl];
        [self.pictureImageView sd_setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"ic_banner_default"]];
        self.numLabel.text = [NSString stringWithFormat:@"数量: %@", _orderInfo.productNum];
        double amountValue = [_orderInfo.discountPrice doubleValue];
        self.priceLabel.text = [NSString stringWithFormat:@"合计:￥%.00lf元", amountValue];
        self.timeLabel.text = _orderInfo.refreshTime;
    }
}

@end
